/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.database.bean;

import com.database.dao.AreaDao;
import com.database.dao.impl.AreaDaoImplement;
import com.database.model.Area;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author diego y Yinna
 */
@ManagedBean(name="areaBean") 
@SessionScoped
public class AreaBean {
        
    private Area area;
    private List<Area> areas;

    
    public AreaBean() {
    
    }
    
    public Area getArea() {
        
        if(area==null){
            area=new Area();
        }
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    public List<Area> getAreas() {
        AreaDao areaDao = new AreaDaoImplement(); 
        areas= areaDao.buscarTodos();
        return areas;
    }
    
     public void prepararInsertar(){
        area = new Area();
    }
    
     public void prepararActualizar(Integer id){
         AreaDao areaDao = new AreaDaoImplement();
         area= areaDao.buscarPorId(id);
    }
    
    public void insertar(){
         
         AreaDao areaDao = new AreaDaoImplement();
         areaDao.insertar(area);
         area = new Area();
    }
    
     public void actualizar(){
         AreaDao areaDao = new AreaDaoImplement();
         areaDao.actualizar(area);
         area = new Area();
    }
     
     public void eliminar(){
         AreaDao areaDao = new AreaDaoImplement();
         areaDao.eliminar(area); 
         area = new Area();
     }
     
      public void prepararEliminar(Integer id){
         AreaDao areaDao = new AreaDaoImplement();
         area= areaDao.buscarPorId(id);
    }
    

}
